#include "threadPool.h"

int taskQueueInit(taskQueue_t *ptaskQueue)
{
    bzero(ptaskQueue, sizeof(taskQueue_t));
    pthread_mutex_init(&ptaskQueue->mutex, NULL);
    pthread_cond_init(&ptaskQueue->cond, NULL);
    return 0;
}

int taskEnQueue(taskQueue_t *ptaskQueue, cmd_t Cmd, int netfd)
{
    task_t *pTask = (task_t *)calloc(1, sizeof(task_t));
    pTask->command = Cmd;
    pTask->netfd = netfd;
    if (0 == ptaskQueue->queueSize)
    {
        ptaskQueue->pFront = pTask;
        ptaskQueue->pRear = pTask;
    }
    else
    {
        ptaskQueue->pRear->pNext = pTask;
        ptaskQueue->pRear = pTask;
    }
    ++ptaskQueue->queueSize;
    return 0;
}

int taskDeQueue(taskQueue_t *ptaskQueue)
{
    task_t *pCur = ptaskQueue->pFront;
    ptaskQueue->pFront = pCur->pNext;
    free(pCur);
    --ptaskQueue->queueSize;
    return 0;
}